import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getxdemo_1/page/tab/home.dart';
import 'package:getxdemo_1/page/tab/center.dart';
import 'package:getxdemo_1/page/obx/obx_count.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    //使用GetMaterialApp
    return GetMaterialApp(
      title: 'Getx',
      initialRoute: '/',
      defaultTransition: Transition.zoom,//跳转动画
      getPages: [
        GetPage(name: "/", page: () => MyApp()),
        GetPage(name: "/home", page: () => HomePage()),
        GetPage(name: "/center", page: () => CenterPage(), transition: Transition.rightToLeft),
        GetPage(name: '/obx1', page: () => ObxCountPage(), transition: Transition.downToUp),
      ],
      home: Scaffold(
        appBar: AppBar(
          title: Text("GetX Title"),
        ),
        body: Center(
          child: Wrap(
            spacing: 10.0,
            children: [
              ElevatedButton(
                  onPressed: () {
                    Get.snackbar("Snackbar 标题", "欢迎使用Snackbar");
                  },
                  child: Text("显示 Snackbar")
              ),
              ElevatedButton(
                  onPressed: () {
                    Get.defaultDialog();
                  },
                  child: Text("显示 Dialog")
              ),
              ElevatedButton(
                child: Text("Bottom Sheet"),
                onPressed: () {
                  Get.bottomSheet(
                      Container(
                        child: Wrap(
                          children: [
                            ListTile(
                              leading: Icon(Icons.wb_sunny_outlined),
                              title: Text("白天模式"),
                              onTap: () {
                                Get.changeTheme(ThemeData.light());
                              },
                            ),
                            ListTile(
                              leading: Icon(Icons.wb_sunny),
                              title: Text("黑夜模式"),
                              onTap: () {
                                Get.changeTheme(ThemeData.dark());
                              },
                            )
                          ],
                        ),
                      )
                  );
                },
              ),
              ElevatedButton(
                  onPressed: (){
                    Get.to(()=>HomePage());
                  },
                  child: Text("home")
              ),
              ElevatedButton(
                  onPressed: (){
                    Get.toNamed('/center');
                  },
                  child: Text("center")
              ),
              ElevatedButton(
                  onPressed: (){
                    Get.toNamed('/obx1');
                  },
                  child: Text("obx计数器")
              ),

            ],
          ),
        ),
      ),
    );
  }
}